package cn.zzz.openplatform.amap.autoconfigure;

import cn.zzz.openplatform.amap.AmapOpenApiService;
import cn.zzz.openplatform.amap.config.AmapProperties;
import cn.zzz.openplatform.amap.model.AmapCredentials;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;
import java.util.stream.Collectors;

@Configuration
@EnableConfigurationProperties(AmapProperties.class)
public class AmapAutoConfiguration {

    @Bean
    public AmapOpenApiService amapOpenApiService(AmapProperties amapProperties) {
        List<AmapProperties.AmapCredentialsProperties> credentialsList = amapProperties.getCredentials();
        List<AmapCredentials> credentials = credentialsList.stream().map(x -> new AmapCredentials(x.getKey(), x.getSig())).collect(Collectors.toList());
        return new AmapOpenApiService(credentials);
    }
}
